namespace Resonator.Domain.Models
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;

	[Serializable]
	public class ResolveResult
	{
		private Resource _original;
		private ResolvedResource _exactMatch;
		private readonly List<ResolvedResource> _partialMatches = new List<ResolvedResource>();
		private int _totalPartialMatches;

		public virtual Resource Original
		{
			get { return _original; }
			set { _original = value; }
		}

		public virtual ResolvedResource ExactMatch
		{
			get { return _exactMatch; }
			set { _exactMatch = value; }
		}

		public virtual IList<ResolvedResource> PartialMatches
		{
			get { return _partialMatches; }
		}

		public virtual int TotalPartialMatches
		{
			get { return _totalPartialMatches; }
			set { _totalPartialMatches = value; }
		}

		public virtual bool HasExactMatch
		{
			get { return _exactMatch != null; }
		}

		public bool HasPartialMatches
		{
			get { return _partialMatches.Count > 0; }
		}

		public virtual bool WasNotFound
		{
			get { return !HasExactMatch && !HasPartialMatches; }
		}

		public static ResolveResult Create(Resource original, IEnumerable<CultureInfo> requiredCultures, Resource exactMatch)
		{
			ResolveResult result = new ResolveResult();
			result.Original = original;
			result.ExactMatch = ResolvedResource.Create( exactMatch, requiredCultures );
			return result;
		}

		public static ResolveResult Create(Resource original, IEnumerable<CultureInfo> requiredCultures, IList<Resource> partialMatches)
		{
			ResolveResult result = new ResolveResult();
			result.Original = original;

			foreach( Resource partialMatch in partialMatches )
			{
				result.PartialMatches.Add( ResolvedResource.Create( partialMatch, requiredCultures ) );
			}

			return result;
		}

		public static ResolveResult Create(Resource original)
		{
			ResolveResult result = new ResolveResult();
			result.Original = original;

			return result;
		}
	}
}